Ext.onReady(function(){
	var fileAttachment = Ext.create('component.file.attachment',{
        objectId: '',
        imageType: "6",
        contextPath:contextPath,
        colspan:2
    });
	var hisAuditRecords = Ext.create('component.his.audit.records',{
		businessId: subscribeId,
		//延期签约编号: BusinessAbnormaEnum
		businessType: "9",
		showGrid: showGrid,
        contextPath:contextPath,
        colspan:2
    });
	   var d = new Date();
	   var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
	   var fromPanelInfo = Ext.create('Ext.form.FormPanel',{
		    renderTo:Ext.getBody(),
		    titleAlign:'center',
	        title:'延期签约申请审批单',
		    border: true,
		    layout:{
		    	 type: 'table',
                 columns: 2,
                 tableAttrs: {　　// 在这儿控制table标签中的Attrs属性
                     border: 1,
                     cellpadding: 5,
                     cellspacing: 1,
                     width: '95%',
                     align: 'center',
                     style: "border:1px solid gray;border-collapse:collapse;margin:0 auto;text-align:center;"
                 },
                 tdAttrs: {　　// 控制td标签的属性，以上用法都是在ext的api中查到，同样的方式可以给tr添加属性
                     width: '100px',
                     height: '40px',
                     style: "padding:5px",
                     valign: 'middle'
                 }
		    },
			 items:[{
				    xtype:'displayfield',
				    fieldLabel: '房产名称',
				    name: 'roomName'
				},{
				    xtype:'displayfield',
				    fieldLabel: '申请日期',
				    value: str
				},{
				    xtype:'displayfield',
				    fieldLabel: '客户名称',
				    name: 'customerName'
				},{
				    xtype:'displayfield',
				    fieldLabel: '房产类型',
				    name: 'propertyTypeName'
				},{
				    xtype:'displayfield',
				    fieldLabel: '计价面积(㎡)',
				    name: 'calculateArea'
				},{
				    xtype:'displayfield',
				    fieldLabel: '折前单价(元)',
				    name: 'conversionPrice'
				},{
				    xtype:'displayfield',
				    fieldLabel: '折前总价(元)',
				    name: 'lumpsumPrice'
				},{
				    xtype:'displayfield',
				    fieldLabel: '折扣金额(元)',
				    name: 'discountAmount'
				},{
				    xtype:'displayfield',
				    fieldLabel: '签约单价(元)',
				    name: 'subscribePrice'
				},{
				    xtype:'displayfield',
				    fieldLabel: '签约总价(元)',
				    name: 'subscribeAmount'
				},{
				    xtype:'displayfield',
				    fieldLabel: '认购金(元)',
				    name: 'depositReceivable'
				},{
				    xtype:'displayfield',
				    fieldLabel: '认购日期',
				    name: 'subscribeDate',
				},{
				    xtype:'displayfield',
				    fieldLabel: '认购转签约日期',
				    name: 'conversionSignDate',
				    id:'conversionSignDate'
				},{
				    xtype:'displayfield',
				    fieldLabel: '认购明细',
				    value: '<a target="_blank" href="'+contextPath+'/customer/subscribe/toView?id='+subscribeId+'&processFlag=processHistoryShow">点击查看认购明细</a>',
				},{
					xtype:'datefield',
				    fieldLabel: '延期到日期',
				    name: 'delayDate',
				    id:'delayDate',
				    allowBlank:false,
			    	blankText:'不能为空',
			    	format: 'Y-m-d',
			    	listeners : {
				    	'select' : function(m, d) {
				    		 var endE=Ext.util.Format.date(m.value,'Y-m-d');
				    		 var conversionSignDate=Ext.getCmp("conversionSignDate").getValue();
				    		 var startE=Ext.util.Format.date(conversionSignDate,'Y-m-d');
				    		 var end = new Date(endE);  
				             var start = new Date(startE); 
				    		 var sjjdpc = Math.round((end.getTime()-start.getTime()) / (86400000));
				    		 Ext.getCmp("delayShowDay").setValue(sjjdpc+"天");
				    	}
				    }
				},{
				    xtype:'displayfield',
				    fieldLabel: '延期天数',
				    id: 'delayShowDay'
				},{
				    xtype:'textarea',
				    fieldLabel: '延期原因',
				    name: 'remark',
				    width:900,
				    align: 'left',
				    id:'reason',
				    colspan:2,
				    allowBlank:false,
			    	blankText:'不能为空'
				},{
				    xtype:'displayfield',
				    fieldLabel: '经纪人',
				    name: 'agentName',
				    colspan:2
				},hisAuditRecords,fileAttachment],
				dockedItems: [{
		            xtype: 'toolbar',
		            dock: 'bottom',
		            ui: 'footer',
		            layout: {
		                pack: 'center'
		            },
		            items: [{
		                minWidth: 80,
		                text: '提交审核',
		                id:'save_button',
		                iconCls:'icon-save',
		                handler:function(){
		                	var form = fromPanelInfo.getForm();
		                	if(form.isValid()){
		                		var fileUrlArr =fileAttachment.getFileArrs();
		                		var params={
			                			'subscribeId':subscribeId,
			                			'remark':Ext.getCmp("reason").getValue(),
			                			delayDate:Ext.getCmp("delayDate").getValue(),
			                			fileUrlArr:fileUrlArr,
			                			imageType: "6",
			                			'token':token
			                	};
		                		
		                		Ext.Ajax.request({
			                		url:contextPath+'/customer/subscribe/submitDelaySinged',
			                		params:params,
			                		callback: function (options, success, response) {
			                			 var obj = JSON.parse(response.responseText);
			                			 if(obj.res=="1"){
			                				   Ext.MessageBox.alert("系统提示", "提交成功! ", function(but) {  
			                					   var tabKey = "del_"+subscribeId;
			     								   parent.TabControlRemove(tabKey);
			    				                }); 
			    						 }else{
			    							 token = obj.obj;
			    							 Ext.MessageBox.alert("系统提示",obj.resMsg); 
			    						 }
			                		}
			                	});
		                		
		                	}
		                }
		            },
		            {
						xtype: "button",
						text : "返回",
						id: "btn_back",
						name: "btn_back",
						icon : contextPath + '/resources/ExtJSicons/shape_move_backwards.png',
						listeners: {
							click: function(){
								  var tabKey = "del_"+subscribeId;
								  parent.TabControlRemove(tabKey);
							}
						}
					}]
		        }
		        ]
	   });
	   
	   fromPanelInfo.getForm().load({
			url:contextPath+'/customer/subscribe/loadRetreat',
			params:{'subscribeId':subscribeId,'businessType':'8'},
			success:function(form, action){
				var obj = action.result.data;
				 var result=Ext.JSON.decode(obj);
				fromPanelInfo.getForm().setValues(result);
			},   
			failure: function(form, action) {
		        Ext.Msg.alert("加载失败", action.result.errorMessage);
		    }

		});
	  
});